﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using BlueMarineWindowsFormsClient.ManagerService;

namespace BlueMarineWindowsFormsClient
{
    public partial class frmEquipmentSelect : Form
    {
        private readonly frmHotelManager parent;
        private List<EquipmentDetail> data;

        public frmEquipmentSelect(frmHotelManager pr)
        {
            data = new List<EquipmentDetail>();
            parent = pr;
            InitializeComponent();
        }

        private void Equipment_Load(object sender, EventArgs e)
        {
            var roomManagement = new ManagerServiceClient();
            data = roomManagement.EquGet(true).ToList();
            var source = new BindingSource {DataSource = data};
            dtaGrdEquipment.DataSource = source;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Dispose();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            var reList = new List<EquipmentDetail>();
            DataGridViewRowCollection rows = dtaGrdEquipment.Rows;
            for (int i = 0; i < rows.Count; i++)
            {
                if (rows[i].Cells[0].Value != null)
                {
                    reList.Add(data[i]);
                }
            }
            foreach (EquipmentDetail re in reList)
            {
                parent.Temp_EquipmentDetails.Add(re);
            }
            parent.viewRoomTypeEquipment();
            Dispose();
        }

        private void EquipmentSelect_FormClosing(object sender, FormClosingEventArgs e)
        {
        }
    }
}